package com.party.admin.task;

import com.party.core.service.gift.IGiftMemberService;
import com.party.core.service.gift.IGiftService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 删除过期礼包和用户的关系
 * Created by wei.li
 *
 * @date 2017/4/12 0012
 * @time 19:48
 */
@Component(value = "quartzGiftMemberDelete")
public class QuartzGiftMemberDelete {
    private static Logger logger = LoggerFactory.getLogger(QuartzGiftMemberDelete.class);

    @Autowired
    private IGiftMemberService giftMemberService;
    @Autowired
    private IGiftService giftService;

    /**
     * 删除过期礼包和用户的关系
     */
    public void deleteRelation() {
        logger.info("删除过期礼包和用户的关系定时任务开始");
        try {
            List<String> giftIds = giftService.getOverdue(null);
            for (String giftId : giftIds) {
                giftMemberService.deleteByGiftId(giftId);
            }
        } catch (Exception e) {
            logger.error("删除过期礼包和用户的关系异常", e);
        }
    }
}
